<?php

class Role_data extends Data {
	private $alias = 'admin-yueshihui-com';
	private $tb = 'role';
	
	private $cols = array('role_id', 'name');
	
	/**
	 * 添加角色
	 * @param unknown_type $params
	 */
	public function createRole($cols) {
		if(!($db = $this->connect($this->alias))) return false;

		if($db->insert($this->tb, $cols)) return $db->lastInsertId();
		else return false;
	}

	/**
	 * 删除角色
	 * @param unknown_type $params
	 */
	public function deleteRole($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->delete($this->tb, $params);
	}
	
	/**
	 * 编辑角色
	 * @param unknown_type $id
	 * @param unknown_type $cols
	 */
	public function editRole($params, $cols) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->update($this->tb, $cols, $params);
	}

	/**
	 * 获取角色信息(单个)
	 * @param unknown_type $params
	 */
	public function role($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->one($this->tb, $this->cols, $params);
	}
	
	/**
	 * 获取角色信息(批量)
	 * @param unknown_type $params
	 */
	public function roles($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->select($this->tb, $this->cols, $params);
	}
	
	/**
	 * 分页获取角色信息
	 * @param unknown_type $page
	 * @param unknown_type $size
	 * @param unknown_type $params
	 * @param unknown_type $orderBy
	 */
	public function page($page, $size, $params = array(), $orderBy = '`id` DESC') {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->page($this->tb, $this->cols, $params, $orderBy, $page, $size);
	}
	/**
	 * 获取角色记录数
	 * @param unknown_type $params
	 */
	public function count($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->count($this->tb, $params);
	}
}